package com.evan.web.autoconfigure;

import com.evan.web.filter.IdempotentParamFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * web自动配置
 *
 * @Description:
 * @Author liudeguang
 */
@Configuration
public class WebAutoConfiguration {

    /**
     * 幂等ID使用：Cookie中标识用户信息的名称, 有值获取对应的，无值获取所有Cookie信息
     */
    @Value("${evan.web.userCookieName}")
    private String userCookieName;

    /**
     * 幂等ID使用：Header中标识用户信息的名称, 有值获取对应的，无值获取所有Header信息
     */
    @Value("${evan.web.userHeaderName}")
    private String userHeaderName;


    /**
     * 配置幂等参数 Filter
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean idempotentParamtFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        IdempotentParamFilter filter = new IdempotentParamFilter(userCookieName, userHeaderName);
        registration.setFilter(filter);
        registration.addUrlPatterns("/*");
        registration.setName("idempotent-filter");
        registration.setOrder(1);
        return registration;
    }


}
